package org.springleaf.security.controller;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springleaf.core.mvc.controller.BaseController;

public abstract class SecurityController extends BaseController{

	/**
	 * 得到当前登录的User
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public <T extends UserDetails> T getUser(){
		Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
		if (principal instanceof UserDetails) {
			return (T)principal;
		} else {
		  return null;
		}
	}
	
}
